import plistlib
from .configs.config import *
import os

current_dir_path = os.path.dirname(__file__)

class Mostone:

    #获取历史版本
    def get_miyo_versions(self):
        return miyo_ipas()

    def get_luka_versions(self):
        return luka_ipas()

    def get_mostone_versions(self):
        return mowang_ipas()

    def get_all_versions(self):
        return all_iaps()

    def get_shiyanshi_all_versions(self):
        return shiyanshi_all_ipas()

    #生成manifest文件, 返回文件路径
    def generate_manifest(self, data, filepath=None):
        if data is None:
            return
        if filepath is None:
            filepath = current_dir_path + "manifests/manifest.plist"
        with open(filepath, "wb") as file:
            plistlib.dump(data, file)
        return filepath

    def generate_miyo_manifest(self, version: object = None):
        data = miyo_manifest_data(version)
        filepath = current_dir_path + "/manifests/miyo/manifest.plist"
        self.generate_manifest(data, filepath=filepath)

    def generate_luka_manifest(self, version=None):
        data = miyo_manifest_data(version)
        filepath = current_dir_path + "/manifests/luka/manifest.plist"
        self.generate_manifest(data, filepath=filepath)